<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * CodeIgniter URL Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/helpers/url_helper.html
 */
// ------------------------------------------------------------------------

/**
 * Site URL
 *
 * Create a local URL based on your basepath. Segments can be passed via the
 * first parameter either as a string or an array.
 *
 * @access	public
 * @param	string
 * @return	string
 */
if (!function_exists('cya')) {

    function cya($uri = '') {
        $CI = & get_instance();
        return $CI->config->site_url($uri);
    }

}
/**
 * _substr 
 *
 * Cut string with paramater length and minword
 *
 * @access	public
 * @param	interger
 * @return	interger
 */
if (!function_exists('_substr')) {

    function _substr($str, $length, $minword = 3) {
        $sub = '';
        $len = 0;

        foreach (explode(' ', $str) as $word) {
            $part = (($sub != '') ? ' ' : '') . $word;
            $sub .= $part;
            $len += strlen($part);

            if (strlen($word) > $minword && strlen($sub) >= $length) {
                break;
            }
        }

        return $sub . (($len < strlen($str)) ? '...' : '');
    }

}

/**
 * GetUserNameByUserId 
 *
 * Cut string with paramater length and minword
 *
 * @access	public
 * @param	interger
 * @return	string
 */
if (!function_exists('GetUserNameByUserId')) {

    function GetUserNameByUserId($user_id) {
        // Get a reference to the controller object
        $CI = get_instance();
        $CI->load->model('news_model', 'news');
        // Call a function of the model
        $UserNameByUserId = $CI->news->LoadUserNameByUserId($user_id);
        return $UserNameByUserId['username'];
    }

}

/**
 * buildStateDropdown 
 *
 * buildStateDropdown drop down caculator save
 *
 * @access	public
 * @param	interger
 * @return	string
 */
if (!function_exists('buildStateDropdown')) {

    function buildStateDropdown($name = '', $state, $value = '', $param = '') {
        $state = array(
            "ACT" => "ACT",
            "NSW" => "NSW",
            "NT" => "NT",
            "QLD" => "QLD",
            "SA" => "SA",
            "TAS" => "TAS",
            "VIC" => "VIC",
            "WA" => "WA");
        return form_dropdown($name, $state, $value, $param);
    }

}

/**
 * buildStateDropdown 
 *
 * buildStateDropdown drop down caculator save
 *
 * @access	public
 * @param	interger
 * @return	string
 */
if (!function_exists('buildSalesDropdown')) {

    function buildSalesDropdown($name = '', $sales, $value = '', $param = '') {
        $sales = array(
            "250,000" => "$ 250,000",
            "300,000" => "$ 300,000",
            "350,000" => "$ 350,000",
            "400,000" => "$ 400,000",
            "450,000" => "$ 450,000",
            "500,000" => "$ 500,000",
            "550,000" => "$ 550,000",
            "600,000" => "$ 600,000",
            "650,000" => "$ 650,000",
            "700,000" => "$ 700,000",
            "750,000" => "$ 750,000",
            "800,000" => "$ 800,000");
        return form_dropdown($name, $sales, $value, $param);
    }

}